package bdz.physics.utils {
	import flash.geom.Point;
	public class Vector {
		private var _x:Number;
		private var _y:Number;
		
		public function Vector(x:Number, y:Number) {
			_x = x;
			_y = y;
		}
		public function clone():Vector {
			return new Vector(_x, _y);
		}
		public function toString():String {
			return "{x:" + _x + ",y:" + _y + "}";
		}
		public function dot(v2:Vector):Number {
			return _x * v2.x + _y * v2.y;
		}
		public function project(v2:Vector):Vector {
			var vect:Vector = v2.clone();
			var dotval:Number = vect.dot(v2);
			vect.multiply(dot(vect) / dotval);
			return vect;
		}
		public function projectLength(v2:Vector):Number {
			return Math.abs(dot(v2) / v2.dot(v2));
		}
		public function normalize():void{
			_x /= length;
			_y /= length;
		}
		public function plus(v2:Vector):Vector {
			return new Vector(_x + v2.x, _y + v2.y);
		}
		public function minus(v2:Vector):Vector {
			return new Vector(_x - v2.x, _y - v2.y);	
		}
		public function multiply(n:Number):void {
			_x *= n;
			_y *= n;
		}
		public function cross(v2:Vector):Number {
			return (_x * v2.y - _y * v2.x);
		}
		
		public function get x():Number {
			return _x;
		}
		public function get y():Number {
			return _y;
		}
		public function get length():Number { 
			return Math.sqrt(_x*_x+_y*_y);
		}
		public function getAngle(v2:Vector):Number {
			return Math.atan2(_y-v2.y, _x-v2.x) * 180 / Math.PI;
		}
		public function get rhn():Vector {
			return new Vector(-_y, _x);
		}
		public function get lhn():Vector {
			return new Vector(_y, -_x);
		}
		
	}
}